package model;
/**
 * This class implements the deck of the poker game, which
 * is simply a list of all the Card objects for the game
 * Every time a deck is initialised, the deck is shuffled
 */

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.io.Serializable;


public class Deck implements Serializable{
	private ArrayList<Card> deck;
	private int numberOfCards;
	
	/**
	 * Constructor: initialise the deck by ensuring every possible
	 * value of each suit is added to the array list, then shuffle
	 * the deck.
	 */
	public Deck() {
		deck = new ArrayList<Card>();
		
		//add every possible card to the deck
		for (Card.CardSuitEnum suit : Card.CardSuitEnum.values()) {
			for (Card.CardRankEnum rank : Card.CardRankEnum.values()) {
				deck.add(new Card(rank, suit));
			}
		}
		
		Collections.shuffle(deck, new Random(System.currentTimeMillis()));
		numberOfCards = deck.size();		
	}
	
	/**
	 * @return the number of cards remaining in the deck
	 */
	public int getNumberOfCards() {
		return numberOfCards;
	}

	/**
	 * Shuffles the deck 
	 */
	public void shuffle() {
		Collections.shuffle(deck);
	}
	
	/**
	 * Remove the last card from the deck
	 * @return card removed from the deck
	 */
	public Card drawCard(){
		numberOfCards--;
		return deck.remove(0);
	}
}
